package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IContactDao;
import com.hy.erp.inventory.pojo.Contact;
import com.hy.erp.inventory.pojo.interfaces.IContact;
import com.hy.erp.inventory.service.interfaces.IContactService;
/**
 * 
 * <ul>
 * <li>开发作者：李冰</li>
 * <li>设计日期：2010-10-13；时间：上午09:17:30</li>
 * <li>类型名称：ContactService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@ Name ( "contactService" )
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class ContactService  extends AbstractBusinessService < IContact > implements IContactService{

	@ Override
	public boolean addContact (
								IContact contact )
	{



		if ( null == contact)
		{
			return true ;
		}
		
		else
		{
			System.out
						.println ("ssssssssssssssssssssssffffffffffffffffhghhhhhhhhhhhhhhhhhhhhhh") ;


			IContactDao contactDao =
			                       ( IContactDao ) this
			                                          .getDao ( IContact.class ) ;
			
			return contactDao
			                .persist ( contact ) ;
		}
		
	
	
	
	}

	@ Override
	public boolean modifyContact (
									IContact contact )
	{


		if ( ( null == contact )
			     || ( null == contact
			                                .getIdentifier ( ) )
			     || ( contact
			                        .getIdentifier ( )
			                        .trim ( )
			                        .length ( ) == 0 ) )
			{
				return true ;
			}
			else
			{

				IContactDao contactDao =
                    ( IContactDao ) this
                                       .getDao ( IContact.class ) ;

		
					
				if ( null == contact )
				{
					throw new ArchitectureFoundationException  (
					                                            "修改实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
				}
				
				
				return (contactDao
				                  .merge ( contact ) != null ) ;
			}
		
	
	
	}

	@ Override
	public Integer removeContact (
									String [ ] contactIds )
	{


		if ( ( null == contactIds)
			     || ( contactIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{


				IContactDao contactDao =
                    ( IContactDao ) this
                                       .getDao ( IContact.class ) ;

				return contactDao
				                .remove ( contactIds ) ;
			}
	
	
	}

	@ Override
	public String [] addContact (
								Object [ ] contact )
	{

		if ( null == contact)
		{
			return null ;
		}
		
		else
		{
			

			IContactDao contactDao =
			                       ( IContactDao ) this
			                                          .getDao ( IContact.class ) ;

			Contact[] contacts=new Contact[contact.length];
						for(int i=0;i<contact.length;i++)
						{
							Contact contact2=( Contact ) contact[i];
							contacts[i]=contact2;
						}
						return contactDao
						                .persist ( contacts ) ;
		}
	}

	@ Override
	public List < IContact > getContactById (
										String [ ] id )
	{
		if ( ( null == id )
			     || ( id.length == 0 ) )
			{
				return null ;
			}
			else
			{
				IContactDao contactDao =
                    ( IContactDao ) this
                                       .getDao ( IContact.class ) ;
	                                        
				return contactDao.findByIdentifier ( id );
				
			}
	}

	@ Override
	public List < IContact > getAllContact ( )
	{
		IContactDao contactDao =
            ( IContactDao ) this
                               .getDao ( IContact.class ) ;
                                    
		return contactDao.findById ( );
	}

	@ Override
	public List < IContact > getContactByQueryName (
													String queryName ,
													Object[] args )
	{
		IContactDao contactDao =
            ( IContactDao ) this
                               .getDao ( IContact.class ) ;
		return contactDao.findByNamedQuery ( queryName , args ) ;
	}

	@ Override
	public String [ ] modifyContact (
										Object [ ] contact )
	{


		if ( null == contact)
		{
			return null ;
		}
		
		else
		{
			

			IContactDao contactDao =
			                       ( IContactDao ) this
			                                          .getDao ( IContact.class ) ;

			Contact[] contacts=new Contact[contact.length];
						for(int i=0;i<contact.length;i++)
						{
							Contact contact2=( Contact ) contact[i];
							contacts[i]=contact2;
						}
						return contactDao
						                .merge  ( contacts ) ;
		}
	
	}

}
